package myapps.ttclient.adapter;

import myapps.ttclient.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class PPTPickingClipArtAdapter extends BaseAdapter{

	private Context mContext;

	private Integer[] mClipArtIDs;
	
	private int mClipArtSelectedID;
	
	public void setmClipArtSelectedID(int id) {
		mClipArtSelectedID = id;
	}

	public PPTPickingClipArtAdapter(Context context, Integer[] clipArtIDs) {
		this.mContext = context;
		this.mClipArtIDs = clipArtIDs;
		mClipArtSelectedID = 0;
	}

	@Override
	public int getCount() {
		return this.mClipArtIDs.length;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	private class ClipArtViewHolder{
		ImageView star;
		ImageView image;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ClipArtViewHolder holder;
		
		if (convertView == null) {
			LayoutInflater layoutInflater = 
				(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			
			convertView = layoutInflater.inflate(R.layout.pickingpointer_rowlayout, null);
			
			holder = new ClipArtViewHolder();
			holder.star = (ImageView) convertView.findViewById(R.id.star);
			holder.image = (ImageView) convertView.findViewById(R.id.image);
		
			convertView.setTag(holder);
		} else {
			holder = (ClipArtViewHolder) convertView.getTag();
		}
	
		holder.image.setImageResource(PPTPickingClipArtAdapter.this.mClipArtIDs[position]);
		
		if(position == mClipArtSelectedID) {
			holder.star.setBackgroundResource(R.drawable.star_selected);
		} else {
			holder.star.setBackgroundResource(R.drawable.star_normal);
		}
		
		return convertView;
	}
}